/**
 * Java中的类
 * 可以在类中定义属性、方法
 */
public class Demo02StudentJava {
    String id;
    String name;
    int age;
    String clazz;

    // 构造方法 对属性进行初始化
    // 无参构造方法
    public Demo02StudentJava() {

    }

    // 重载构造方法
    public Demo02StudentJava(String id, String name, int age) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.clazz = "自由分班";
    }

    // 重载构造方法
    public Demo02StudentJava(String id, String name, int age, String clazz) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.clazz = clazz;
    }

    @Override
    // 重写父类的构造方法
    public String toString() {
        return "Demo02StudentJava{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public void printClazz() {
        System.out.println(this.name + "," + this.clazz);
    }

    public static void main(String[] args) {
        // 传入参数 创建对象 该对象会默认获得类中定义的属性及方法
        Demo02StudentJava stu1 = new Demo02StudentJava();
        Demo02StudentJava zs = new Demo02StudentJava("001", "zs", 20);
        System.out.println(stu1);
        System.out.println(zs);

        Demo02StudentJava ls = new Demo02StudentJava("002", "ls", 21);
        Demo02StudentJava ww = new Demo02StudentJava("003", "ww", 22, "文科一班");

        ls.printClazz();
        ww.printClazz();

    }

}
